<?php

die();

include 'common.php';
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$deviceid = $_REQUEST['deviceid'];
$UUID = $_REQUEST['uuid'];
$androidid = $_REQUEST['androidid'];


$qid = uniqid('ac_'.$username);
$qid = substr(md5($qid), 8, 16);
$conn;

chkndata($username);
chkndata($password);
chksymbol($deviceid);
chksymbol($androidid);
chksymbol($UUID);

$conn = connect2db();

$errorcode = 0;
$result = mysql_query("select * from userinfo where username='$username' and password='$password'");
$row = mysql_fetch_array($result);

$key = md5($username."remix");
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];

mysql_free_result($result);
if($row)
{
	setcookie('username', $username, time() + 60*60*24*5);
	setcookie('token', $qid, time() + 60*60*24*5);
	$errorcode = 3;
	if(mysql_query("update userinfo set llip='$ip',uuid='$UUID',u_deviceid='$deviceid',androidid='$androidid',changetime='$time',ukey='$key',token='$qid' where username='$username' and password='$password'"))
	{
		$errorcode = 1;
		safelog($username, 'LOGIN_USER', $conn);
	}
}else{
	$errorcode = 2;
	$token = '0';
}
echo json_encode(array('errorcode'=>$errorcode,'username'=>$username, 'token'=>$qid));

mysql_close($conn);
?>